package com.haoshuang.zhouzhoubang.ui.activity


import android.Manifest
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.core.widget.addTextChangedListener
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.sdk.android.oss.ClientException
import com.alibaba.sdk.android.oss.ServiceException
import com.alibaba.sdk.android.oss.common.utils.OSSUtils
import com.alibaba.sdk.android.oss.model.PutObjectRequest
import com.alibaba.sdk.android.oss.model.PutObjectResult
import com.blankj.utilcode.util.ImageUtils
import com.haoshuang.zhouzhoubang.databinding.ActivityFeedBackBinding
import com.haoshuang.zhouzhoubang.ui.adapter.ChooseImageAdapter
import com.haoshuang.zhouzhoubang.ui.vm.FeedBackViewModel
import com.haoshuang.zhouzhoubang.utils.MultiMediaChooseUtils
import com.haoshuang.zhouzhoubang.utils.OSSUploadUtils

import com.luck.picture.lib.entity.LocalMedia
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.clickWithTrigger


/**
 *  意见反馈界面
 */
class FeedBackActivity : BaseVMActivity<FeedBackViewModel, ActivityFeedBackBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.apply {
            appBar.ivBack.clickWithTrigger { finish() }
            appBar.tvTitle.text = "意见反馈"


            etComment.addTextChangedListener {
                textView19.text = "${etComment.text.toString().length}/200"
            }

            tvSubmit.setOnClickListener {
                var comment = etComment.text.toString()
                if (comment.isNullOrBlank()) {
                    toast("反馈内容不能为空")
                    return@setOnClickListener
                }
                val imageList = recyclerView.getMediaList()
                if (imageList.isEmpty()) {
                    toast("请选择照片")
                    return@setOnClickListener
                }
                val pics = imageList.joinToString(","){it.url?:""}
                vm.getNet("comment" to comment, "pics" to pics)
            }
        }


    }

    override fun initData() {
    }

    override fun startObserve() {
        vm.getNet.observeState(this) {
            onLoading { showLoading() }
            onError { code, msg ->
                dismissLoading()
                toast(msg)
            }
            onSuccess {
                dismissLoading()
                toast("提交成功")
                finish()
            }
        }
    }
}